package com.example.newheze.User;

import android.app.Fragment;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.ListView;

import com.example.newheze.R;

import java.util.ArrayList;
import java.util.List;

public class UserActivity extends Fragment {
    ListViewAdapter listViewAdapter;
    ListView listView;
    public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, Bundle savedInstanceState) {
        View view = inflater.inflate(R.layout.activity_user, container, false);
        listViewAdapter = new ListViewAdapter(this.getActivity(), getData());
        listView = view.findViewById(R.id.listview);
        listView.setAdapter(listViewAdapter);
        listView.setOnItemClickListener(new AdapterView.OnItemClickListener(){
            public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
                if(position==1){
                    //item监听事件
                }
            }
        });
        return view;
    }
    private List<ListViewModel> getData(){
        List<ListViewModel> list=new ArrayList<ListViewModel>();
        ListViewModel listViewModel=new ListViewModel();
        listViewModel.setUsername("列表项1");
        list.add(listViewModel);
        //一个对象就是一个列表项，可创建多个
        ListViewModel listViewModel1=new ListViewModel();
        listViewModel1.setUsername("列表项2");
        list.add(listViewModel1);

        ListViewModel listViewModel2=new ListViewModel();
        listViewModel2.setUsername("列表项3");
        list.add(listViewModel2);
        return list;
    }
}
